//===================================
//File: ML.h
//Multilist Definition
//Name: Smirnova O.P.
//Date: 09.02.12, v.1.0
//===================================
#ifndef MLIST_H
#define MLIST_H
#include "MListEl.h"
#include <iostream>
template <class T>
class MultiList{
private:
	MultiListElem<T>* rootListA;
	MultiListElem<T>* rootListB;
	MultiListElem<T>* rootListC;


	MultiListElem<T>* lastA;
	MultiListElem<T>* lastB;
	MultiListElem<T>* lastC;
public:
	MultiList() // Передаём исходный список
	{
		rootListA = 0;
		rootListB = 0;
		rootListC = 0;
	}
	void writeList() // вывод списков из которых составляется мультисписок
	{
		std::cout << "List1(main list in right order):" << std::endl;
		int i=0;
		MultiListElem<T> *temp = rootListA;
		while(rootListA!=0)
		{
			std::cout << i++ << ")" << std::endl <<
			rootListA->getValue();
			std::cout << std::endl << " ";
			rootListA = rootListA->getElema();
		}
		std::cout << std::endl << "List1." << std::endl;
		rootListA = temp;
		std::cout << std::endl << "Press enter to continue" << std::endl;
		std::cout << "List2(list of positive elems in right order):" << std::endl;
		temp = rootListB;
		i=1;
		while(rootListB!=0)
		{
			std::cout << i++ << ")" << std::endl <<
			rootListB->getValue();
			std::cout << std::endl << " ";
			rootListB = rootListB->getElemb();
		}
		std::cout << std::endl << "List2." << std::endl;
		rootListB = temp;
		std::cout << std::endl << "Press enter to continue" << std::endl;
		std::cout << "List3(list of nonpositive elems in inverse order):" << std::endl;
		temp = rootListC;
		i=1;
		while(rootListC!=0)
		{
			std::cout << i++ << ")" << std::endl <<
			rootListC->getValue();
			std::cout << std::endl << " ";
			rootListC = rootListC->getElemc();
		}
			std::cout << std::endl << "List3." << std::endl;
		rootListC = temp;
	}
	MultiListElem<T>* getRootListA()
		{
			return rootListA;
		}
	MultiListElem<T>* getRootListB()
		{
			return rootListB;
		}
	MultiListElem<T>* getRootListC()
		{
			return rootListC;
		}
	short isEmpty()
	{
		if(rootListA == 0) return 1;
		else return 0;
	}
	void addElem(T value) // добавить элемент в мультисписок
	{
			MultiListElem<T> *el = new MultiListElem<T>(value);
			if(rootListA == 0)
				{
					rootListA = el;
					lastA = el;
				}
				else
				{
					lastA->setElema(el);
					lastA = el;
				}
			if(value>0)
			{
				if(rootListB == 0)
				{
					rootListB = el;
					lastB = el;
				}
				else
				{
					lastB->setElemb(el);
					lastB = el;
				}
			}
			else
			{
				if(rootListC == 0)
				{
					rootListC = el;
					lastC = el;
				}
				else
				{
					lastC->setElemc(el);
					lastC = el;
				}
			}
	}

};
#endif










